package com.changgou.goods.controller;

import com.changgou.common.constant.StatusCode;
import com.changgou.common.vo.Result;
import com.changgou.goods.pojo.Para;
import com.changgou.goods.pojo.Spec;
import com.changgou.goods.pojo.Template;
import com.changgou.goods.service.Temp_spec_paraService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/temp")
public class Temp_spec_paraController {

    @Autowired
    private Temp_spec_paraService temp_spec_paraService;

    @GetMapping("/{pageNum}/{pageSize}")
    public Result<List<Template>> findPage(@PathVariable("pageNum") Integer pageNum,@PathVariable("pageSize") Integer pageSize){
        //分页的模板列表
        PageInfo<Template> pageInfo = temp_spec_paraService.findPage(pageNum, pageSize);

        //模板列表
        List<Template> templateList = pageInfo.getList();

        //规格数量
        List<Spec> specList = temp_spec_paraService.findSpec();

        //参数数量
        List<Para> paraList = temp_spec_paraService.findPara();

        for (Template template : templateList) {
            for (Spec spec : specList) {
                template.setSpecNum(spec.getSeq());
                break;
            }
            for (Para para : paraList) {
                template.setParaNum(para.getSeq());
                break;
            }
        }
        pageInfo.setList(templateList);
        return new Result<List<Template>>(true, StatusCode.OK,"查询成功！",pageInfo);
    }
}
